<template>
	<view>
		<view class="u-wrap">
			<cu-custom bgColor="bg-gradual-blue" :isBack="true">
				<block slot="backText">返回</block>
				<block slot="content">维修故障库</block>
			</cu-custom>
			<view  style="background-color: white;" class="u-search-box">
				<view slot="top" class="search">
					<u-search placeholder="请输入描述信息" v-model="KeyWord" @custom='search()' @search='search()'></u-search>
				</view>
			</view>
			<view class="emptyImageP" v-if="SceneExperienceTypeArry.length==0">
				<image class="emptyImage" :src="emptyIcon"></image>
			</view>
			<view v-if="SceneExperienceTypeArry.length>0" class="u-menu-wrap">
				<scroll-view style="width: 30%;" scroll-y scroll-with-animation class="u-tab-view menu-scroll-view" :scroll-top="scrollTop">
					<view v-for="(item,index) in SceneExperienceTypeArry" :key="index" class="u-tab-item" :class="[current==index ? 'u-tab-item-active' : '']"
					 :data-current="index" @tap.stop="swichMenu(index,item.ConfigKey)">
						<text class="u-line-1">{{item.COnfigValue}}</text>
					</view>
				</scroll-view>
				<view style="width: 70%;margin-bottom: 100rpx;">
					<view v-if="SceneExperienceType.length>0">
						<view v-for="(item, index) in SceneExperienceType" class="goods-item-wrap">
							<view class="goods-content-wrap">
								<view v-if="false" class="goods-name">
									<view class="goods-name-title">{{item.ExperienceTitle}}</view>
									<view class="select-icon"></view>
								</view>
								<view class="goods-stock-wrap">
									<view class="goods-stock">{{item.ExperienceDesc}}</view>
								</view>
								<view  class="publish-goods-btn1" @click="choise(item.ExperienceDesc)">选择</view>
							</view>
						</view>
					</view>	
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import request from '@/common/request.js';
export default {
	data() {
		return {
			scrollTop: 0, //tab标题的滚动条位置
			current: 0, // 预设当前项的值
			menuHeight: 0, // 左边菜单的高度
			menuItemHeight: 0, // 左边菜单item的高度
			
			ConfigKey:'',
			KeyWord:'',
			SceneExperienceTypeArry:[],
			SceneExperienceType:[],
			emptyIcon:this.$request22.baseUrl1+'/Resource/Sg/empty/empty.png'
		};
	},
	mounted() {
		console.log('mounted')
	},
	computed: {
	},
	onLoad() {
		let that=this
		that.getSceneExperienceType();
	},
	onShow(){
	},
	methods: {
		search(e){
			let that=this
			that.getSceneExperience(that.ConfigKey);
		},
		getImg() {
			return Math.floor(Math.random() * 35);
		},
		// 点击左边的栏目切换
		async swichMenu(index,ConfigKey) {
			if(index == this.current) return ;
			this.current = index;
			// 如果为0，意味着尚未初始化
			if(this.menuHeight == 0 || this.menuItemHeight == 0) {
				await this.getElRect('menu-scroll-view', 'menuHeight');
				await this.getElRect('u-tab-item', 'menuItemHeight');
			}
			// 将菜单菜单活动item垂直居中
			this.scrollTop = index * this.menuItemHeight + this.menuItemHeight / 2 - this.menuHeight / 2;
			
			this.ConfigKey=ConfigKey
			this.getSceneExperience(ConfigKey)
		},
		// 获取一个目标元素的高度
		getElRect(elClass, dataVal) {
			new Promise((resolve, reject) => {
				const query = uni.createSelectorQuery().in(this);
				query.select('.' + elClass).fields({size: true},res => {
					// 如果节点尚未生成，res值为null，循环调用执行
					if(!res) {
						setTimeout(() => {
							this.getElRect(elClass);
						}, 10);
						return ;
					}
					this[dataVal] = res.height;
				}).exec();
			})
		},
		getSceneExperienceType(){
			let that=this
			uni.showLoading({
				title: '加载中...'
			})
			let opts = {
				url: 'SpareApi/GetSceneExperienceType',
				method: 'get'
			};
			request.httpTokenRequest(opts).then(res => {
				uni.hideLoading();
				if(res.data.code == 1){
					that.SceneExperienceTypeArry=res.data.data
					if(res.data.data.length>0){
						that.ConfigKey=res.data.data[0].ConfigKey
						that.getSceneExperience(that.ConfigKey)
					}
				}
				else{
					uni.showToast({ title: res.data.msg, icon: 'none' });
				}
			});
		},
		getSceneExperience(ConfigKey){
			let that=this
			uni.showLoading({
				title: '加载中...'
			})
			let opts = {
				url: 'SpareApi/GetSceneExperience',
				method: 'get'
			};
			let parames = {
				ConfigKey: ConfigKey,
				KeyWord:that.KeyWord
			};
			request.httpTokenRequest(opts,parames).then(res => {
				uni.hideLoading();
				if(res.data.code == 1){
					that.SceneExperienceType=res.data.data
				}
				else{
					uni.showToast({ title: res.data.msg, icon: 'none' });
				}
			});
		},
		setNav(goodsNav) {
			console.log('setNav')
			let that=this
			that.goodsNav=goodsNav
			that.getSceneExperience(goodsNav)
		},
		choise(ExperienceDesc){
			uni.$emit('ExperienceDesc',ExperienceDesc)
			console.log('准备传过去的值：'+ExperienceDesc)
			uni.navigateBack({
				delta: 1 //返回层数，2则上上页
			});
		},
	}
};
</script>

<style lang="scss" scoped>
	.u-wrap {
		height: calc(100vh);
		/* #ifdef H5 */
		height: calc(100vh - var(--window-top));
		/* #endif */
		display: flex;
		flex-direction: column;
	}
	
	.u-search-box {
		padding: 18rpx 30rpx;
	}
	
	.u-menu-wrap {
		flex: 1;
		display: flex;
		//overflow: hidden;
	}
	
	.u-search-inner {
		background-color: rgb(234, 234, 234);
		border-radius: 100rpx;
		display: flex;
		align-items: center;
		padding: 10rpx 16rpx;
	}
	
	.u-search-text {
		font-size: 26rpx;
		color: $u-tips-color;
		margin-left: 10rpx;
	}
	
	.u-tab-view {
		width: 300rpx;
		height: 100%;
	}
	
	.u-tab-item {
		height: 110rpx;
		background: #f6f6f6;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 26rpx;
		color: #444;
		font-weight: 400;
		line-height: 1;
	}
	
	.u-tab-item-active {
		position: relative;
		color: #000;
		font-size: 30rpx;
		font-weight: 600;
		background: #fff;
	}
	
	.u-tab-item-active::before {
		content: "";
		position: absolute;
		border-left: 4px solid $u-type-primary;
		height: 32rpx;
		left: 0;
		top: 39rpx;
	}
	
	.u-tab-view {
		height: 100%;
	}
	
	.right-box {
		background-color: rgb(250, 250, 250);
	}
	
	.page-view {
		padding: 16rpx;
	}
	
	.class-item {
		margin-bottom: 30rpx;
		background-color: #fff;
		padding: 16rpx;
		border-radius: 8rpx;
	}
	
	.item-title {
		font-size: 30rpx;
		color: $u-main-color;
		font-weight: bold;
		margin: 10rpx 0;
	}
	
	.item-menu-name {
		font-weight: normal;
		font-size: 24rpx;
		color: $u-main-color;
	}
	
	.item-container {
		display: flex;
		flex-wrap: wrap;
	}
	
	.thumb-box {
		width: 33.333333%;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		margin-top: 20rpx;
		margin-bottom: 10rpx;
	}
	
	.item-menu-image {
		width: 120rpx;
		height: 120rpx;
		border-radius: 100rpx;
	}
	.cu-tag.badge{
		top:-10rpx !important;
		right:30rpx !important;
	}
	.goods-item-wrap-now{
		//border:2px solid #00B52A;
	}
	.goods-item-wrap {
		height: 300rpx;
		border-radius: 8rpx;
		background: #FFFFFF;
		display: flex;
		padding: 24rpx;
		margin: 12rpx;
		position: relative;
		//width:100%;
		.goods-content-wrap{
			width: 100%;
		}
		.goods-name {
			width: 100%;
			font-size: 32rpx;
			font-weight: bold;
			display: flex;
			position: relative;
			border-bottom: 1px solid #F3F4F8;
			padding-bottom: 20rpx;
		}
		.goods-name-title{
			display: block;
			float: left;
		}
		.goods-name-type{
			display: block;
			float:right;
			color: #3B69FD;
			margin-right: 20rpx;
		}
		.goods-stock-wrap {
			display: flex;
			color: #969696;
			font-size: 24rpx;
			margin-top: 20rpx;
			justify-content: space-between;
		}
		
		.goods-stock {
			margin-right: 24rpx;
			font-size: 28rpx;
			color: #636571;
			line-height: 32rpx;
		}
		.goods-stock-isok{
			margin-right: 10rpx;
			font-size: 38rpx;
			color: #00B52A;
			line-height: 32rpx;
			font-weight: 700;
		}
		.goods-stock-middle{
			margin-right: 10rpx;
			font-size: 38rpx;
			color: #636571;
			line-height: 32rpx;
			font-weight: 700;
		}
		.goods-stock-notok{
			margin-right: 24rpx;
			font-size: 38rpx;
			color: #F53F3E;
			line-height: 32rpx;
			font-weight: 700;
		}
		.goods-stock-time {
			margin-right: 24rpx;
			font-size: 28rpx;
			color: #e7612e;
			padding-bottom: 20rpx;
		}
		.goods-shangxiaxian {
			font-size:24rpx;
			color: #3F71C4;
			margin-top: 14rpx;
		}
		
		.goods-price1 {
			font-size:26rpx;
			color: #3B69FD;
			margin-top: 20rpx;
			font-weight:500;
			width: 160rpx;
			display: block;
			float:left;
			background-color: #D0D9F7;
			border-radius: 4rpx;
			text-align: center;
			height: 54rpx;
			line-height: 54rpx;
		}
		.goods-price2 {
			font-size:26rpx;
			color: #15C9CA;
			margin-top: 20rpx;
			font-weight:500;
			width: 160rpx;
			display: block;
			float:left;
			background-color: #C8ECEC;
			border-radius: 4rpx;
			text-align: center;
			height: 54rpx;
			line-height: 54rpx;
		}
		.goods-option-item {
			padding: 8rpx 16rpx;
			border-radius: 36rpx;
			font-size: 24rpx;
			margin-top: 24rpx;
		}
	}
	
.wrap {
	display: flex;
	flex-direction: column;
	height: calc(100vh - var(--window-top));
	width: 100%;
}
.swiper-box {
	flex: 1;
}
.swiper-item {
	height: 100%;
}

	.goods-option-item {
		padding: 8rpx 16rpx;
		border-radius: 36rpx;
		font-size: 24rpx;
		margin-top: 24rpx;
	}

	.goods-option-item:not(:last-child) {
		margin-right: 24rpx;
	}

	.goods-option-item-action {
		background: #f1f0fe;
		color: #6991ce;
	}

	.goods-item-wrap {
		margin-bottom: 24rpx;
	}

	.goods-header-wrap {
		display: flex;
		align-items: center;
		padding: 24rpx;
		background: #FFFFFF;
		margin-bottom: 10rpx;
	}
	.goods-header-item{
		width:49%;
		text-align: center;
	}
	.goods-header-item-active{
		font-size: 30rpx;
		font-color: #333333;
		font-weight: bold;
		position: relative;
	}
	.goods-header-item-active::after{
		position: absolute;
		left: 50%;
		right: 0;
		background: #4372fe;
		height: 8rpx;
		content: "";
		bottom: -12rpx;
		width: 60rpx;
		margin-left: -30rpx;
		border-radius: 200rpx;
	}
	.goods-header-item-action {
		// font-size: 32rpx;
		// font-color: #333333;
		// font-weight: bold;
		position: relative;
	}

	.goods-header-item-action::after {
		// position: absolute;
		// left: 0;
		// right: 0;
		// background: #4372fe;
		// height: 8rpx;
		// content: "";
		// bottom: -12rpx;
	}
	.extraPosition{
		position: absolute;
		right: -5rpx;
		top: -10rpx;
		font-size: 20rpx;
		padding: 0rpx 10rpx;
		height: 28rpx;
		color: #ffffff;
		background-color: #dd514c;
		display: inline-flex;
		align-items: center;
		justify-content: center;
	}
	
	.publish-goods-btn {
		width:160rpx;
		background: #e7612e;
		color: #FFFFFF;
		height: 54rpx;
		line-height: 54rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 82rpx;
		float:right;
		margin-right: 20rpx;
		margin-top: 20rpx;
	}
	
	.publish-goods-btn1 {
		width:160rpx;
		background: #3B69FD;;
		color: #FFFFFF;
		height: 54rpx;
		line-height: 54rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 82rpx;
		float:right;
		margin-right: 20rpx;
		margin-bottom: 20rpx;
		position: absolute;
		bottom: 20rpx;
		right: 10rpx;
	}
	
	.publish-goods-btn2 {
		width:160rpx;
		background: #00B52A;;
		color: #FFFFFF;
		height: 54rpx;
		line-height: 54rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 82rpx;
		float:right;
		margin-right: 20rpx;
		margin-top: 20rpx;
	}
	
	
	.select-icon{
		border-bottom: 3rpx solid #999;
		border-right: 3rpx solid #999;
		width: 16rpx;
		height: 16rpx;
		transform: rotate(-45deg);
		position: absolute;
		right: 20rpx;
		top: 14rpx;
	}
	.emptyImage{
		//480  356
		width: 480rpx;
		height: 356rpx;
		margin: auto;
		margin-left: 50%;
		margin-top: 200rpx;
		left: -240rpx;
		position: absolute;
	}
</style>

